<template>
   <div class="comment">
     <textarea  rows="10" placeholder="请输入你的评价" v-model="content">

     </textarea>
     <div class="imgList_wrapper">
       <div class="imgList" v-for="(item,index) of imgList" :key="index">
        <img :src="item" mode="aspectFill" class="introduce_item_pic">
       </div>
        <img src="../../../static/images/addPic.png" mode="aspectFill" @click="uploadImg">
     </div>
     <div class="save_wrapper">
       <div class="save" @click="save">发布</div>
     </div>
   </div>
</template>

<script>
  export default{
    name:'comment',
    data() {
      return {
        imgList:[],
        imgIdList:[],
        content:'',
        order_num:'',
        goods_id:'',
        goods_spu:''
      }
    },
    methods: {
      uploadImg(){
        let _this=this
        wx.chooseImage({
          success(res) {
            const tempFilePaths = res.tempFilePaths
            wx.uploadFile({
              url: 'https://study.rzkeji.com/api/file/upload-image', // 仅为示例，非真实的接口地址
              filePath: tempFilePaths[0],
              name: 'photo',
              header: {
              'content-type': 'application/json' // 默认值
              },
              success(res) {
                const data = JSON.parse(res.data)
                _this.imgList.push(data.data.img_url)
                _this.imgIdList.push(data.data.id)
              }
            })
          }
        })
      },
       async save(){
        var userToken=wx.getStorageSync('userToken')
        let res=await this.$request.postData('/goods/userComment',{order_num:this.order_num,goods_id:this.goods_id,content:this.content,img_ids:this.imgIdList,user_token:userToken,goods_spu:this.goods_spu})
        if(res.data.level=='success'){
          this.$currency.showToast(res.data.message,'success',1500);
          setTimeout(()=>{
            this.$currency.redirectTo('/pages/order/main?status=4')
          },2000)
        }
      }
    },
    onLoad(options){
      this.order_num=options.order_num;
      this.goods_id=options.goods_id;
      this.goods_spu=options.goods_spu
    }
  }
</script>

<style lang="scss" scoped>
  textarea{
    width:100%;
    border-top:1px solid #eee ;
    border-bottom:1px solid #eee ;
    vertical-align:center !important;
    box-sizing: content-box !important;
    font-size: 14px;
  }
  .imgList_wrapper{
    display:flex;
    flex-wrap: wrap;
    img{
        width: 80px;
        height: 80px;
        margin:5px;
      }
    .imgList{
      display: flex;
      flex-wrap: wrap;
    }
  }
  .save_wrapper{
    width:100%;
    margin-top:50px;
    .save{
      margin:0 auto;
      width:200px;
      height: 40px;
      line-height: 40px;
      font-size: 25px;
      border-radius: 10px;
      background: orange;
      color:#fff;
      text-align: center;
    }
  }
</style>
